﻿using EfCoreTest.Repository;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EfCoreTest
{
    public class Program
    {
        public static void Main(string[] args)
        {
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

            var connection = "Filename=./sqlitedb.db";

            try
            {
                using (DataContext context = new DataContext(connection))
                {

                    //context.Database.Migrate();


                    //var users = new UserInfo[]
                    //{
                    //    new UserInfo() {
                    //        UserName = "小白",
                    //        Age = 28,
                    //        Remark = "人"
                    //     },
                    //    new UserInfo() {
                    //        UserName = "小黑",
                    //        Age = 20,
                    //        Remark = "小非洲"
                    //     },
                    //    new UserInfo() {
                    //        UserName = "小周",
                    //        Age = 20,
                    //        Remark = "唐人街"
                    //     },
                    //};
                    //context.Users.AddRange(users);
                    //context.SaveChanges();

                    var users = context.Users.AsNoTracking().ToList();
                    foreach (var item in users)
                    {
                        Console.WriteLine("Id:{0};姓名:{1};年龄:{2};备注:{3}", item.Id, item.UserName, item.Age, item.Remark);
                    }
                }

            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.WriteLine(ex.Source);
                Console.WriteLine(ex.StackTrace);
                if (ex.InnerException != null)
                {
                    Console.WriteLine(ex.InnerException.Message);
                    Console.WriteLine(ex.InnerException.Source);
                    Console.WriteLine(ex.InnerException.StackTrace);
                }
            }
            Console.WriteLine("complete");
            Console.ReadKey();
        }
    }
}
